package library.and.xps.com.step.m.model;

import java.util.ArrayList;
import java.util.Date;

import library.and.xps.com.step.util.CommonUtils;
import library.and.xps.com.step.util.DateUtil;

public class WeeklyRecord {
    private ArrayList<DaliyRecord> week = new ArrayList<>();
    private int stepsAverage = 0;
    private double milesCount = 0;
    private String DateSpanDes = "";//title 上的日期 [4月19-4月23]
    private String SimpleDateSpanDes = "";//lable 上的日期缩写 [4/19-4/23]

    public WeeklyRecord() {
    }

    public String getDateSpanDes() {

        if (week == null || week.size() <= 0) return "";
        StringBuilder sb = new StringBuilder();

        Date d = week.get(0).getDate();
        sb.append(DateUtil.trimZero(DateUtil.formatDateSimpleWord(d.getTime())));

        sb.append("-");

        Date de = week.get(week.size() - 1).getDate();
        sb.append(DateUtil.trimZero(DateUtil.formatDateSimpleWord(de.getTime())));
        DateSpanDes = sb.toString();
        
        return DateSpanDes;
    }

    public String getSimpleDateSpanDes() {
        if (week == null || week.size() <= 0) return "";
        StringBuilder sb = new StringBuilder();
        sb.append(DateUtil.trimZero(DateUtil.formatDateSimple(week.get(0).getTimeStamp())));
        sb.append("-");
        sb.append(DateUtil.trimZero(DateUtil.formatDateSimple(week.get(week.size() - 1).getTimeStamp())));
        SimpleDateSpanDes = sb.toString();
        return SimpleDateSpanDes;
    }

    public void setSimpleDateSpanDes(String simpleDateSpanDes) {
        SimpleDateSpanDes = simpleDateSpanDes;
    }

    public ArrayList<DaliyRecord> getWeek() {
        return week;
    }

    public void setWeek(ArrayList<DaliyRecord> week) {
        this.week = week;
    }

    //添加一天
    public void insertOneDay(DaliyRecord d) {
        week.add(d);
    }

    public int getStepsAverage() {
        try {
            int stepsCount = 0;
            if (week != null && week.size() > 0) {
                for (DaliyRecord daliyRecord : week) {
                    stepsCount += daliyRecord.getStepCount();
                }
            }

            stepsAverage = stepsCount / 7;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }

        return stepsAverage;
    }

    public double getMilesCount() {
        int stepsCount = 0;
        try {
            if (week != null && week.size() > 0) {
                for (DaliyRecord daliyRecord : week) {
                    stepsCount += daliyRecord.getStepCount();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return 0.0;
        }
        milesCount = CommonUtils.stepToMiles(stepsCount);
        return milesCount;
    }

    public void setMilesCount(int milesCount) {
        this.milesCount = milesCount;
    }


    public void setDateSpanDes(String dateSpanDes) {
        DateSpanDes = dateSpanDes;
    }
}
